<template>
    <div style="outline: none" tabindex="1" @keydown.stop.prevent="keyup" @focus="focus" @blur="blur" id="payPassword_container" class="alieditContainer clearfix" data-busy="0">
        <div class="sixDigitPassword-box" style="width: 180px;">
            <i style="width: 29px; border: none"><b v-show="passwordArr[0]" style="visibility: visible;"></b></i>
            <i style="width: 29px;"><b v-show="passwordArr[1]" style="visibility: visible;"></b></i>
            <i style="width: 29px;"><b v-show="passwordArr[2]" style="visibility: visible;"></b></i>
            <i style="width: 29px;"><b v-show="passwordArr[3]" style="visibility: visible;"></b></i>
            <i style="width: 29px;"><b v-show="passwordArr[4]" style="visibility: visible;"></b></i>
            <i style="width: 29px;"><b v-show="passwordArr[5]" style="visibility: visible;"></b></i>
            <span :style="{left: this.leftNum + 'px', visibility: this.isShow}" :class="active"
                  style="width: 29px;" id="cardwrap" data-role="cardwrap"></span>
        </div>
    </div>
</template>

<script>
    export default {
        name: 'paypwd',
        data: function () {
            return {
                isShow: 'hidden',
                pwdlength: 6,
                password: "",
                passwordArr: [],
                keymap: {
                    48: "0",
                    49: "1",
                    50: "2",
                    51: "3",
                    52: "4",
                    53: "5",
                    54: "6",
                    55: "7",
                    56: "8",
                    57: "9",
                    96: "0",
                    97: "1",
                    98: "2",
                    99: "3",
                    100: "4",
                    101: "5",
                    102: "6",
                    103: "7",
                    104: "8",
                    105: "9",
                }
            }
        },
        computed: {
            active: function () {
                if (this.passwordArr.length < 6) {
                    return 'active';
                }
                else {
                    return '';
                }
            },
            leftNum: function () {
                if (this.passwordArr.length < 6) {
                    return 30 * this.passwordArr.length;
                }
                else {
                    return 30 * 5;
                }
            }
        },
        methods: {
            clear: function () {
                this.password = ""
                this.passwordArr = []
            },
            focus: function (e) {
                this.isShow = 'visible'
            },
            blur: function (e) {
                this.isShow = 'hidden'
            },
            keyup: function (e) {
                if (e.keyCode === 8 && this.passwordArr.length > 0) {
                    this.passwordArr.pop();
                    this.password = this.passwordArr.join('');
                }
                else if (this.passwordArr.length < this.pwdlength && ((e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 96 && e.keyCode <= 105))) {
                    this.passwordArr.push(this.keymap[e.keyCode]);
                    this.password = this.passwordArr.join('');
                }
                else {
                    //nothing
                }
            }
        }

    }
</script>

<style>
    .clearfix:after {
        clear: both;
    }

    .clearfix:before, .clearfix:after {
        content: " ";
        display: table;
    }

    .alieditContainer {
        position: relative;
    }

    .sixDigitPassword-box {

        cursor: text;
        background: #fff;
        outline: none;
        position: relative;
        padding: 8px 0;
        height: 15px;
        border: 1px solid #cccccc;
        border-radius: 2px;
    }

    .sixDigitPassword-box i {
        float: left;
        display: block;
        padding: 4px 0;
        height: 7px;
        border-left: 1px solid #cccccc;
    }

    .sixDigitPassword-box .active {
        background: url('../assets/password-blink.gif') no-repeat center center;
    }

    .sixDigitPassword-box b {
        display: block;
        margin: 0 auto;
        width: 7px;
        height: 7px;
        overflow: hidden;
        visibility: hidden;
        background: url('../assets/passeord-dot.png') no-repeat;
    }

    .sixDigitPassword-box span {
        position: absolute;
        display: block;
        left: 0px;
        top: 0px;
        height: 30px;
        border: 1px solid rgba(82, 168, 236, .8);
        border: 1px solid #00ffff \9;
        border-radius: 2px;
        visibility: hidden;
        -webkit-box-shadow: inset 0px 2px 2px rgba(0, 0, 0, 0.75), 0 0 8px rgba(82, 168, 236, 0.6);
        box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(82, 168, 236, 0.6);
    }
</style>
